package mlp.game.scootaloo;

import com.overkill.game.Renderable;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;

public class Shadow {
	
	private Renderable object;
	private float width = 96;
	private float height = 12; 
	private float ground;
	private float maxJumpHeight;
	private float offsetX;
	private float offsetY;
	private RectF shadow;
	private Paint paint;	
	
	public Shadow(Renderable object, float ground, float maxJumpHeight, float offsetX, float offsetY, Paint paint) {
		this.object = object;
		this.ground = ground;
		this.maxJumpHeight = maxJumpHeight;
		this.offsetX = offsetX;
		this.offsetY = offsetY;
		this.paint = paint;
		this.shadow = new RectF(0, 0, this.width, this.height);	
	}

	public void setSize(float width, float height){
		this.width = width;
		this.height = height;
	}

	public void update(){
		float centerX = object.getFrame().centerX();
		float factor = ((ground -  object.getHeight() -  object.getPosition().y) / maxJumpHeight + 1);
		float _width = width / factor;

		shadow.left = centerX - (_width / 2) + offsetX;
		shadow.top = ground - offsetY;
		shadow.right = shadow.left + _width;
		shadow.bottom = shadow.top + height / factor;		
	}
	
	public void draw(Canvas canvas){
		canvas.drawOval(shadow, paint);
	}
	
	
	
}
